﻿namespace LeetCode_Learn
{
    /// <summary>
    /// 获取两个奇数
    /// </summary>
    public class Part04_GetTwoOddNumber
    {
        public static int[] Get(int[] arr)
        {
            if (arr == null)
                throw new ArgumentNullException("arr不可为空!");
            if (arr.Length < 2)
                return arr;

            int eor = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                eor ^= arr[i];
            }

            int _eor = 0;
            int rightOne = eor & (~eor + 1);

            for (int i = 0; i < arr.Length; i++)
            {
                if ((arr[i] & rightOne) == 0)
                {
                    _eor ^= arr[i];
                }
            }
            int a = eor ^ _eor;
            int b = eor ^ a;
            return new int[] { a, b };
        }
    }
}
